﻿using INTEX.DataBase;
using ReflectionStudio.Components.UserControls;
using ReflectionStudio.Core.Events;
using ReflectionStudio.Core.Helpers;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OracleClient;
using System.Windows;
using System.Windows.Data;
using System.Windows.Input;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for SETUPABON.xaml
    /// </summary>
    public partial class ITXSETUP
    { 
/*  
        #region=====vwFUNCTION
        CollectionViewSource vwFUNCTION
        {
            get
            {
                return (CollectionViewSource)this.TryFindResource("vwFUNCTION");
            }
        }
        DataRow dwFUNCTION
        {
            get
            {
                if (vwFUNCTION.View == null)
                    return null;
                if ((DataRowView)vwFUNCTION.View.CurrentItem == null)
                    return null;
                return ((DataRowView)vwFUNCTION.View.CurrentItem).Row;
            }
        }
        #endregion

      
        #region=====vwICC_FUNCTIONS
        CollectionViewSource vwICC_FUNCTIONS
        {
            get
            {
                return (CollectionViewSource)this.TryFindResource("vwICC_FUNCTIONS");
            }
        }
        DataRow dwEFUNCTION
        {
            get
            {
                if (vwICC_FUNCTIONS.View == null)
                    return null;
                if ((DataRowView)vwICC_FUNCTIONS.View.CurrentItem == null)
                    return null;
                return ((DataRowView)vwICC_FUNCTIONS.View.CurrentItem).Row;
            }
        }
        #endregion
        #region=====vwTMPFUNCTION
        CollectionViewSource vwTMPFUNCTION
        {
            get
            {
                return (CollectionViewSource)this.TryFindResource("vwTMPFUNCTION");
            }
        }
        DataRow dwTMPFUNCTION
        {
            get
            {
                if (vwTMPFUNCTION.View == null)
                    return null;
                if ((DataRowView)vwTMPFUNCTION.View.CurrentItem == null)
                    return null;
                return ((DataRowView)vwTMPFUNCTION.View.CurrentItem).Row;
            }
        }
        #endregion  
        
        #region=====vwFOLDER=======
        CollectionViewSource vwFOLDER
        {
            get
            {
                return (CollectionViewSource)this.TryFindResource("vwFOLDER");
            }
        }
        DataRow dwFOLDER
        {
            get
            {
                if (vwFOLDER.View == null)
                    return null;
                if ((DataRowView)vwFOLDER.View.CurrentItem == null)
                    return null;
                return ((DataRowView)vwFOLDER.View.CurrentItem).Row;
            }
        }
        #endregion
        */
        private void butFunctionITXLoad_Click(object sender, RoutedEventArgs e)
        {
            DataSet setResult = null;
            try
            {
                setResult = m_Data.LoadITXFunction(Mandant);
                SetMaster.Clear();
                SetMaster.Merge(setResult, false, MissingSchemaAction.Ignore);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            } 
        }
        private void butFunctionLoad_Click(object sender, RoutedEventArgs e)
        {
            DataSet setResult = null;
            try
            {
                setResult = m_Data.LoadFunction();
                SetMaster.Clear();
                SetMaster.Merge(setResult, false, MissingSchemaAction.Ignore);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            finally
            {
                SetMaster.Clear();
                SetMaster.Merge(setResult, false, MissingSchemaAction.Ignore);
                SetMaster.AcceptChanges();
            }
        }
        private void butFunctionCopy_Click(object sender, RoutedEventArgs e)
        {
            DataSet setResult = null;
            try
            {
                if (dwFUNCTION == null)
                    return;
                DataRow dwNewFolder = SetDetail.ICC_FUNCTIONS.NewICC_FUNCTIONSRow();
                dwNewFolder.ItemArray =dwFUNCTION.ItemArray;
                dwNewFolder["ROWNID"] = "0";
                SetDetail.ICC_FUNCTIONS.Rows.Add(dwNewFolder);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        private void butFunctionEdit_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                SetDetail.Clear();
                SetDetail.Merge(SetMaster.ICC_FUNCTIONS);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);

            }
            finally
            {

            }
        }
        private void butFunctionCopyAll_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                SetDetail.Clear();
                SetDetail.Merge(SetMaster.ICC_FUNCTIONS);
                foreach (DataRow RX in SetDetail.ICC_FUNCTIONS.Rows)
                {
                    RX["ROWNID"] = "0";
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);

            }

        }
        private void butFunctionSave_Click(object sender, RoutedEventArgs e)
        {
            DataSet setResult = null;
            try
            {
                m_Data.SaveFunctionSetup(SetDetail, "00");
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        private void butFolderITXLoad_Click(object sender, RoutedEventArgs e)
        {
            DataSet setResult = null;
            try
            {
                setResult = m_Data.LoadITXFolder(Mandant);
                SetMaster.Clear();
                SetMaster.Merge(setResult, false, MissingSchemaAction.Ignore);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            finally
            {
                SetMaster.Clear();
                SetMaster.Merge(setResult, false, MissingSchemaAction.Ignore);
                SetMaster.AcceptChanges();
            }
        }
        private void butFolderLoad_Click(object sender, RoutedEventArgs e)
        {
            DataSet setResult = null;
            try
            {
                setResult = m_Data.LoadFolder(Mandant);
                SetMaster.Clear();
                SetMaster.Merge(setResult, false, MissingSchemaAction.Ignore);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            finally
            {
                SetMaster.Clear();
                SetMaster.Merge(setResult, false, MissingSchemaAction.Ignore);
                SetMaster.AcceptChanges();
            }
        }
        private void butFolderCopy_Click(object sender, RoutedEventArgs e)
        {
            DataSet setResult = null;
            try
            {
                if (dwFOLDER == null)
                    return;
                DataRow dwNewFolder = SetDetail.ICC_FOLDERS.NewICC_FOLDERSRow();
                dwNewFolder.ItemArray = dwFOLDER.ItemArray;
                dwNewFolder["ROWNID"] = "0";
                SetDetail.ICC_FOLDERS.Rows.Add(dwNewFolder);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        private void butFolderSave_Click(object sender, RoutedEventArgs e)
        {
            DataSet setResult = null;
            try
            {
                m_Data.SaveFolderSetup(SetDetail, "00");
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }


        private void butFolderCopyAll_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                SetDetail.Clear();
                SetDetail.Merge(SetMaster.ICC_FOLDERS);
                foreach (DataRow RX in SetDetail.ICC_FOLDERS.Rows)
                {
                    RX["ROWNID"] = "0";
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);

            }
            finally
            {

            }
        }
      

        private void txtFunctionType_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                if (dwTMPFUNCTION == null)
                    return;
                string tag = txtType.Text.Trim();
                dwTMPFUNCTION["NAMESPACE"] = "WPFExcelReport";
                dwTMPFUNCTION["TYPE"] = tag;
                dwTMPFUNCTION["FULLNAME"] = tag;
                dwTMPFUNCTION["FILENAME"] = tag + ".dll";
            }
        }
        
       
    }
}
